package com.ruoyi.activiti.controller;

import java.util.List;

import com.ruoyi.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.activiti.domain.Attend;
import com.ruoyi.activiti.service.IAttendService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 员工基本考勤信息Controller
 * 
 * @author lifan
 * @date 2021-04-08
 */
@Controller
@RequestMapping("/activiti/attend")
public class AttendController extends BaseController
{
    private String prefix = "activiti/attend";

    @Autowired
    private IAttendService attendService;

    @RequiresPermissions("activiti:attend:view")
    @GetMapping()
    public String attend()
    {
        return prefix + "/attend";
    }

    /**
     * 查询员工基本考勤信息列表
     */
    @RequiresPermissions("activiti:attend:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Attend attend)
    {
        startPage();
        List<Attend> list = attendService.selectAttendList(attend);
        return getDataTable(list);
    }

    /**
     * 导出员工基本考勤信息列表
     */
    @RequiresPermissions("activiti:attend:export")
    @Log(title = "员工基本考勤信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Attend attend)
    {
        List<Attend> list = attendService.selectAttendList(attend);
        ExcelUtil<Attend> util = new ExcelUtil<Attend>(Attend.class);
        return util.exportExcel(list, "attend");
    }
    /**
     * 下载模板
     */
    @RequiresPermissions("activiti:attend:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<Attend> util = new ExcelUtil<Attend>(Attend.class);
        return util.importTemplateExcel("考勤信息");
    }
    /**
     * 导入
     */
    @RequiresPermissions("activiti:attend:import")
    @PostMapping("/importAttend")
    @ResponseBody
    public AjaxResult importAttend(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Attend> util = new ExcelUtil<Attend>(Attend.class);
        List<Attend> attendList = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getSysUser().getLoginName();
        String message = attendService.importAttend(attendList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    /**
     * 新增员工基本考勤信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存员工基本考勤信息
     */
    @RequiresPermissions("activiti:attend:add")
    @Log(title = "员工基本考勤信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Attend attend)
    {
        return toAjax(attendService.insertAttend(attend));
    }

    /**
     * 修改员工基本考勤信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {

        Attend attend = attendService.selectAttendById(id);
        mmap.put("attend", attend);
        return prefix + "/edit";
    }

    /**
     * 修改保存员工基本考勤信息
     */
    @RequiresPermissions("activiti:attend:edit")
    @Log(title = "员工基本考勤信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Attend attend)
    {
        return toAjax(attendService.updateAttend(attend));
    }

    /**
     * 删除员工基本考勤信息
     */
    @RequiresPermissions("activiti:attend:remove")
    @Log(title = "员工基本考勤信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(attendService.deleteAttendByIds(ids));
    }
}
